package com.timoon.component.panel.jqgrid.action;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.form.Form;

import com.timoon.component.panel.jqgrid.JqGridPanel;
import com.timoon.component.panel.jqgrid.panel.DetailsPanel;

public class DetailsButton extends RecordIdsReceiverAjaxButton {
	private static final long serialVersionUID = 6172846089164875061L;
	
	private ModalWindow win;
	
	private JqGridPanel mainPanel;
	
	public DetailsButton(String id,JqGridPanel mainPanel) {
		super(id,mainPanel);
		// TODO Auto-generated constructor stub
		if(!mainPanel.isButtonVisible(JqGridPanel.DETAIL_BUTTON_ENABLE)){
			this.setVisible(false);
		}
		
		this.mainPanel=mainPanel;
		
		this.win=mainPanel.getWin();
	}
	@Override
	protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
		// TODO Auto-generated method stub
		super.onSubmit(target, form);
	}
	
	/**
	 * 从mainPanel获取查看明细面板
	 * @param id
	 * @param win
	 * @param service
	 * @return
	 */
	private DetailsPanel getDetailsPanel(String id,JqGridPanel mainPanel,String recordId){
		return mainPanel.getDetailsPanel(id, mainPanel,recordId);
	}
	@Override
	protected void onReceivedRecordId(String id,AjaxRequestTarget target) {
		// TODO Auto-generated method stub
		win.setTitle("查看明细"+id);
		win.setContent(this.getDetailsPanel(win.getContentId(),mainPanel,id));
		win.show(target);
	}

}
